VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "ListenerQueue"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Public Enum QueueType
    qtSystem
    qtExternal
End Enum

Private vm_SystemQueues As Queue
Private vm_ExternalQueues As Queue


Public Sub enqueueToQueue(ByVal pr_Obj As Variant, pr_DestQueue As QueueType)
Select Case pr_DestQueue
Case qtSystem
    vm_SystemQueues.enqueue pr_Obj
Case qtExternal
    vm_ExternalQueues.enqueue pr_Obj
End Select
End Sub

Public Function hasElement(ByVal pr_Element As Variant) As Boolean
hasElement = (vm_ExternalQueues.hasElement(pr_Element)) Or (vm_SystemQueues.hasElement(pr_Element))
End Function

Public Function removeElementAndReturnSuccess(ByVal pr_Element As Variant) As Boolean
If vm_ExternalQueues.hasElement(pr_Element) Then
    removeElementAndReturnSuccess = vm_ExternalQueues.removeElementAndReturnSuccess(pr_Element)
Else
    If vm_SystemQueues.hasElement(pr_Element) Then
        removeElementAndReturnSuccess = vm_SystemQueues.removeElementAndReturnSuccess(pr_Element)
    End If
End If
End Function

Public Function dequeue() As Variant
If vm_SystemQueues.numItems = 0 Then
    dequeue = vm_ExternalQueues.dequeue
Else
    dequeue = vm_SystemQueues.dequeue
End If
End Function

Public Function getIterator() As LLIterator
'Since this queue combines two queues, the stack iterator from the first queue must system queue must supercede the stack iterator from the external
Dim vl_SystemIterator As LLIterator
Dim vl_ExternalIterator As LLIterator
Dim vl_ReturnIterator As LLIterator

Set vl_ExternalIterator = vm_ExternalQueues.getIterator
Set vl_SystemIterator = vm_SystemQueues.getIterator


vl_SystemIterator.linkEndWithIterator vl_ExternalIterator

Set getIterator = vl_SystemIterator
End Function

Private Sub Class_Initialize()
Set vm_ExternalQueues = New Queue
Set vm_SystemQueues = New Queue
End Sub

Private Sub Class_Terminate()
Set vm_ExternalQueues = Nothing
Set vm_SystemQueues = Nothing
End Sub
